<template>
  <el-container class="content">
    <el-aside width="auto">
      <MenuBar :menuInfo='menuInfo' :defaultActive="defaultActive"/>
    </el-aside>
    <el-main>
      <el-scrollbar>
        <router-view></router-view>
      </el-scrollbar>
    </el-main>
  </el-container>
</template>

<script>
  import MenuBar from '@/components/Menu/index'

  export default {
    name: 'Index',
    components: {MenuBar},
    data() {
      return {
        menuInfo: [],
        userId: "",
        defaultActive: "123"
      }
    },
    methods: {
      initMenuList() {
        ajax.get(apis.admin.getMenuList).then(res => {
          if (res.success === true) {
            this.menuInfo = res.data
            this.setCurrentActiveMenu()
          } else {
            this.$message({
              message: res.message,
              type: 'error',
              showClose: true
            });
          }
        })
      },
      setCurrentActiveMenu() {
        let routePath = this.$route.path
        if (this.menuInfo !== []) {
          this.menuInfo.map(itemM => {
            if (itemM.childMenuVOList) {
              let menuIndexId = itemM.childMenuVOList.findIndex(item => item.menuUrl === routePath)
              if (menuIndexId >= 0) {
                this.defaultActive = typeof itemM.childMenuVOList[menuIndexId].id === "string" ? itemM.childMenuVOList[menuIndexId].id : itemM.childMenuVOList[menuIndexId].id.toString()
              }
            }
          })
        }
      }
    },
    created() {
      this.initMenuList()
      this.setCurrentActiveMenu()
    },
    mounted() {
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    .el-aside {
      overflow: hidden;
    }
    .el-main {
      padding-bottom: 0;
      overflow: hidden;
      background-color: #f9f9f9;
      .el-scrollbar {
        height: calc(100vh - 100px);
      }
    }
  }
</style>
